package com.battle.service.repository.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.battle.pojo.entity.TrainingPersonSetting;
import com.battle.pojo.vo.trainingPersonSetting.GetTrainingPersonSettingListVo;
import com.battle.service.mapper.TrainingPersonSettingMapper;
import com.battle.service.repository.in.TrainingPersonSettingRepository;
import nirvana.core.repository.Repository;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
    import com.battle.pojo.dto.trainingPersonSetting.*;
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
* 【描 述】：
* 【环 境】：J2SE
* 【详 细】：
*
*/
@Service
public class TrainingPersonSettingRepositoryImpl extends Repository< TrainingPersonSettingMapper , TrainingPersonSetting> implements TrainingPersonSettingRepository {

private final TrainingPersonSettingMapper mapper;

public TrainingPersonSettingRepositoryImpl(TrainingPersonSettingMapper mapper) {
this.mapper = mapper;
}

    /**
    * 搜索训练人员设置
    * @param dto
    * @return
    */
    @Override
    public Page<GetTrainingPersonSettingListVo> selectTrainingPersonSetting(SelectTrainingPersonSettingDto dto){

    return mapper.selectTrainingPersonSetting(dto);
    }

@Override
public  Map<Long, TrainingPersonSetting> getMap(List<Long> ids){
    Map<Long, TrainingPersonSetting> map = new HashMap<>();

    if (CollectionUtil.isNotEmpty(ids)) {
        List<TrainingPersonSetting> list =listByIds(ids);
        if (CollectionUtil.isNotEmpty(list)) {
        map = list.stream().collect(Collectors.toMap(TrainingPersonSetting::getId, pojo -> pojo));
         }
        }
        return map;
    }

    @Override
    public List<TrainingPersonSetting> getPersonSettingByDepartmentId(Long departmentId) {
        return mapper.selectList(new LambdaQueryWrapper<>(TrainingPersonSetting.class)
                .eq(TrainingPersonSetting::getDepartmentId, departmentId)
                .eq(TrainingPersonSetting::getIsDelete, false));
    }
}